package com.dk.controller;

import com.dk.pojo.TCategory;
import com.dk.service.TCategoryServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("tCategoryController")
public class TCategoryController {

    @Autowired
    private TCategoryServiceI tCategoryServiceI;

    //跳转图书分类列表
    @RequestMapping("list")
    public String listGet(){
        return "tCategory/list";
    }

    //查询图书分类
    @RequestMapping("getInfoServer")
    @ResponseBody
    public List<TCategory> getInfoServer(){
        List<TCategory> list = tCategoryServiceI.getInfoServer();
        return list;
    }

    //跳转图书分类增加页面
    @RequestMapping("insertInfo")
    public String insertInfo(){
        return "tCategory/add";
    }

    //确认增加图书分类
    @RequestMapping("saveById")
    @ResponseBody
    public int saveById(TCategory tCategory){
        tCategoryServiceI.saveById(tCategory);
        return 1;
    }

    //回显图书分类
    @RequestMapping("updateInfo/{catId}")
    public String getUpdateInfo(@PathVariable("catId")Integer catId, Model model){
        TCategory tCategory = tCategoryServiceI.getUpdateInfo(catId);
        model.addAttribute("tCategory",tCategory);
        return "tCategory/update";
    }

    //确认修改分类
    @RequestMapping("updateById")
    @ResponseBody
    public  int updateById(TCategory tCategory){
        tCategoryServiceI.updateById(tCategory);
        return 1;
    }

    //删除分类
    @RequestMapping("deleteById/{catId}")
    @ResponseBody
    public int deleteById(@PathVariable("catId")Integer catId){
        tCategoryServiceI.deleteById(catId);
        return 1;
    }
}
